package embuzzled.g5;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;


public class SingleColorPuzzle implements Puzzle
{
	private int height;
	private int width;
	
	int coloringStrategy;
	
	boolean isSpecificColored = false;
	Color color;
	boolean[][] colorBooleanMap;
	
	String solution;
	
	public SingleColorPuzzle(int height, int width)
	{
		this.height = height;
		this.width = width;
	}
	
	public SingleColorPuzzle(boolean[][] map, Color c)
	{
		this.height = map.length;
		this.width = map[0].length;
		
		colorBooleanMap = map;
		color = c;
	}
	
	/**
	 * Takes in array of cell coords to color
	 * @param map
	 */
	public void setColorMap(boolean[][] map) {
		colorBooleanMap = map;
	}
	
	/**
	 *  Returns a color map describing this puzzle.
	 *  Cells we colored in are in this puzzle's color.
	 *  Cells we haven't colored have the color Constants.COLOR_CLEAR.
	 */
	public Color[][] returnLocalColorMap()
	{
		System.out.println(height + ", " + width + ", " + color);
		Color[][] map = new Color[height][width];
		
		for(int i = 0; i < height; i++)
			for(int j = 0; j < width; j++)
			{
				if(colorBooleanMap[i][j])
				{
					//System.out.println("Color");
					map[i][j] = color;
				}
				else
				{
					map[i][j] = Constants.COLOR_CLEAR;
				}
			}
		
		return map;
	}
	
	public void setColor(Color c) {
		color = c;
		
	}
	
	public void setColor(Color[] possibleColors)
	{
		Color c;
		Random r = new Random();
		
		switch(coloringStrategy)
		{
		case Constants.COLORING_MONOCOLOR:
			c = possibleColors[r.nextInt(possibleColors.length)];
			setColor(c);
			break;
		case Constants.COLORING_RANDOM:
			c = possibleColors[r.nextInt(possibleColors.length)];
			setColor(c);
			break;
		case Constants.COLORING_ROTATE:
			setColor(possibleColors[0]);
			break;
		default:
			break;
		}
	}
	
	public Color getColor() {
		return color;
	}

	public int getHeight() {
		return height;
	}

	public int getWidth() {
		return width;
	}
	
	/**
	 * For now, stand-alone puzzles can be placed anywhere.
	 */
	public int[] getPlacementStrategies()
	{
		int[] strategy = new int[1];
		strategy[0] = Constants.PLACEMENT_ANYWHERE;
		
		return strategy;
	}
	
	public void setSolution(String s)
	{
		solution = s;
	}
	
	public String getSolution()
	{
		return solution;
	}
	
	/**
	 *  This type of puzzle is never made of multiple components.
	 */
	public boolean isComposite()
	{
		return false;
	}
	
	/**
	 * Method required for compatibility with Puzzle interface.
	 * The placement method should only call getComponents()
	 * if isComposite() returns true.
	 */
	public ArrayList<PuzzleComponent> getComponents()
	{
		return null;
	}
	
}
